home *** CD-ROM | disk | FTP | other *** search
- :
- # vmailtool
- #
- # James T. Perkins
- #
- # $Id: vmailtool,v 1.15 91/03/01 14:03:01 jamesp Exp $
-
- TMP=/tmp/vmailtool.$$
-
- NOMAILICON="${NOMAILICON:-/usr/include/images/nomail.icon}"
- MAILICON="${MAILICON:-/usr/include/images/mail.icon}"
- BOLD_FONT="${BOLD_FONT:-/usr/lib/fonts/fixedwidthfonts/screen.b.14}"
- REVISION="V`set $Revision: 1.15 $ ; echo \$2`"
- DATE="`set $Date: 91/03/01 14:03:01 $ ; echo \$2`"
-
- if stty 2>&1 >/dev/tty | grep -s tostop
- then
- echo "vmailtool: vmailtool and 'stty tostop' are incompatible. See the man page." >&2
- exit 1
- fi
-
- trap 'status=$?; rm $TMP; exit $status' 0 1 2 15
-
- cat >$TMP <<END-OF-TOOLTOOL-SCRIPT
- /*
- * vmailtool $REVISION tooltool file
- * James Perkins $DATE
- */
-
- #define APPLICATION "vmail"
- #define VMAILICON "/usr/public/bin/vmailicon"
- #define ICON_MAIL "$MAILICON"
- #define ICON_NOMAIL "$NOMAILICON"
- #define MAIL_LABEL '$MAILICON'
- #define NOMAIL_LABEL '$NOMAILICON'
- #define ICON_UP '/usr/public/icons/up'
- #define ICON_DOWN '/usr/public/icons/down'
- #define ICON_LEFT '/usr/public/icons/left'
- #define ICON_RIGHT '/usr/public/icons/right'
- #define LABEL "Vmail/MH Tool - $REVISION - $DATE - JTP"
- #define ROW_SIZE 34
- #define COL_SIZE 80
- #define BOLD_FONT "$BOLD_FONT"
-
- /*
- * icon_flag_up/icon_flag_down - these strings are echoed to the tty when mail
- * arrives or is incorporated. They cause the tooltool icon to change to
- * indicate arrival of mail, or no mail.
- */
-
- #define icon_flag_up format("%s %s", VMAILICON, ICON_MAIL)
- #define icon_flag_down format("%s %s", VMAILICON, ICON_NOMAIL)
-
- /*
- * types of dialog boxes. We only have one dialog box, and it switch-hits
- * between each kind of dialog box. This is necessary becuase tooltool
- * eats up one extra window for each dialog box -- if there were a dialog
- * box for each one of these, tooltool would eat up a lot of windows.
- */
-
- #define REFILE 0
- #define COMP 1
- #define REPL 2
- #define FORW 3
- #define SEARCH 4
- #define NEW_FOLDER 5
- #define PIPE 6
- #define DIST 7
- #define BURST 8
- #define SORT 9
-
- /*
- * define overall application
- */
-
- application APPLICATION
- icon ICON_NOMAIL
- label LABEL
- size ROW_SIZE by COL_SIZE characters
-
- /*
- * Do the following when we start up
- */
- initialize {
- /*
- * initialize dialog box
- */
-
- dialog_box_first_time = 1;
-
- /*
- * get mpath (path of system maildrop) from MAILPATH, MAIL, or USER
- * environment variables.
- */
-
- if (length(mpath = getenv("MAILPATH")) > 0) {
- endpath = index(mpath, "?");
- mpath = substr(mpath, 1, (endpath - 1));
- }
- else if (length(mpath = getenv("MAIL")) > 0) {
- ;
- }
- else {
- user = getenv("USER");
- mpath = format("/usr/spool/mail/%s", user);
- }
-
- /*
- * get NEWMAILCMD environment variable. The shell command in
- * newmailcmd is executed every time new mail arrives.
- */
-
- newmailcmd = getenv("NEWMAILCMD");
- lastsize = 0;
- cursize = 0;
-
- /*
- * Pop up flag (both the icon and the mail label) if there's mail
- */
-
- remove mail_label;
- if (exists(mpath)) {
- st = stat(mpath);
- cursize = st["size"];
- if (cursize > lastsize) {
- system(icon_flag_up);
- remove nomail_label;
- display mail_label;
- }
- }
- lastsize = cursize;
-
- /*
- * Set up new mail test timer, based on MAILCHECK environment variable.
- * timeout will never exceed 60 seconds.
- */
-
- if ((interval = getenv("MAILCHECK")) < 60) {
- interval = 60;
- }
- }
-
-
- /*
- * Do the following when the window is opened
- */
-
- open {}
-
- /*
- * Do the following when the window is closed
- */
-
- close {}
-
- /*
- * Do the following asychronously, whenever the "interval" timer times out.
- */
-
- timer {
- /*
- * Pop up flag if there's mail (both icon and mail label)
- */
-
- if (exists(mpath)) {
- st = stat(mpath);
- cursize = st["size"];
- if (cursize > lastsize) {
- system(icon_flag_up);
- remove nomail_label;
- display mail_label;
- if (length(newmailcmd) > 0) {
- system(newmailcmd);
- }
- }
- else {
- if (cursize == 0 && lastsize != 0) {
- remove mail_label;
- display nomail_label;
- }
- }
- }
- lastsize = cursize;
- }
-
- /*
- * Define all buttons and menus for the application
- */
-
- gadgets
- /*
- * Button labels are right justified and not adjusted.
- */
-
- right
- ragged
-
- /*
- * Gadgets at default places
- */
-
- button mail_label /* Copy of tooltool icon */
- at 5 5
- normal MAIL_LABEL {
- close;
- }
- control "quit" {
- exit;
- }
- end_button
- button /* incorporate mail */
- normal "inc" {
- remove mail_label;
- display nomail_label;
- system(icon_flag_down);
- send "i";
- }
- shift "inc show" {
- remove mail_label;
- display nomail_label;
- system(icon_flag_down);
- send "i ";
- }
- end_button
- label /* blank lines to leave room for arrows */
- ""
- end_label
- label
- ""
- end_label
- label
- ""
- end_label
- label
- ""
- end_label
- label
- "-MESSAGE-" : BOLD_FONT
- end_label
- button /* show current message */
- normal "show" {
- send " ";
- }
- shift "print" {
- printer = getenv("PRINTER");
- if (length(printer) > 0) {
- printer = format(" -P%s", printer);
- }
- send(format("|(echo Printing...; lpr%s)\n ", printer));
- }
- control "pipe" {
- dialog_type = PIPE;
- popup dialog_box;
- }
- end_button
- button /* delete current message */
- normal "delete" {
- send "d";
- }
- shift "undo delete" {
- send "u";
- }
- end_button
- button /* refile current message */
- normal "refile" {
- dialog_type = REFILE;
- popup dialog_box;
- }
- shift "again" {
- if (length(refile_cmd) > 0) {
- send(refile_cmd);
- }
- else {
- dialog_type = REFILE;
- popup dialog_box;
- }
- }
- control "to prev folder" {
- send "R";
- }
- end_button
- label
- ""
- end_label
- button /* compose new message */
- normal "comp" {
- send "c\n";
- }
- shift "comp..." {
- dialog_type = COMP;
- popup dialog_box;
- }
- end_button
- button /* reply to current message */
- normal "repl" {
- send "a\n";
- }
- shift "repl..." {
- dialog_type = REPL;
- popup dialog_box;
- }
- end_button
- button /* forward current message */
- normal "forw" {
- send "f\n";
- }
- shift "forw..." {
- dialog_type = FORW;
- popup dialog_box;
- }
- end_button
- menu "misc"
- "rescan" {
- send "^R";
- }
- "edit" {
- send "e";
- }
- "burst" {
- send "b\n";
- }
- "burst..." {
- dialog_type = BURST;
- popup dialog_box;
- }
- "dist" {
- send "t\n";
- }
- "dist..." {
- dialog_type = DIST;
- popup dialog_box;
- }
- end_menu
- label
- ""
- end_label
- label
- "-FOLDER-" : BOLD_FONT
- end_label
- button /* search folder for subject line */
- normal "search" {
- if (length(search_cmd) > 0) {
- send(search_cmd);
- }
- else {
- beep;
- }
- }
- shift "forward..." {
- search_dir = "/";
- dialog_type = SEARCH;
- popup dialog_box;
- }
- control "backward..." {
- search_dir = "?";
- dialog_type = SEARCH;
- popup dialog_box;
- }
- end_button
- button /* go to new folder */
- normal "new fold" {
- dialog_type = NEW_FOLDER;
- popup dialog_box;
- }
- shift "alternate" {
- if (length(new_folder_cmd) > 0) {
- send "G";
- }
- else {
- dialog_type = NEW_FOLDER;
- popup dialog_box;
- }
- }
- end_button
- Menu "misc" /* misc folder commands */
- "List All" {
- send "F";
- }
- "Pack" {
- send "z";
- }
- "Sort" {
- send "S\n";
- }
- "Sort..." {
- dialog_type = SORT;
- popup dialog_box;
- }
- "Inactivate" {
- send "v";
- }
- end_menu
-
- /*
- * Gadgets at particular places
- */
-
- button nomail_label /* copy of tooltool icon */
- at 5 5
- normal NOMAIL_LABEL {
- close;
- }
- control "quit" {
- exit;
- }
- end_button
- button /* make prev message current */
- at 30 110
- normal ICON_UP {
- send "k";
- }
- shift "home" {
- send "H";
- }
- end_button
- button /* go to prev page of messages */
- at 10 130
- normal ICON_LEFT {
- send "\b";
- }
- shift "prev folder" {
- send "p";
- }
- end_button
- button /* go to next page of messages */
- at 50 130
- normal ICON_RIGHT {
- send "\r";
- }
- shift "next folder" {
- send "n";
- }
- end_button
- button /* make next message current */
- at 30 150
- normal ICON_DOWN {
- send "j";
- }
- shift "last line" {
- send "L";
- }
- end_button
- end_gadgets
-
- /*
- * Here's the dialog box that does everything.
- * The first time it is opened, it removes everything in it except for
- * the "done" and "cancel" buttons.
- * Then, any time it is opened it adds the fields it needs, and when it
- * is closed it removes them.
- */
-
- dialog dialog_box
- size 24 by 43 characters
- open {
- if (dialog_box_first_time == 1) {
- dialog_box_first_time = 0;
- remove refile_label;
- remove refile_folder;
- remove comp_label;
- remove comp_opts;
- remove forw_label;
- remove forw_opts;
- remove repl_label;
- remove repl_opts;
- remove search_label;
- remove search_regex;
- remove new_folder_label;
- remove new_folder;
- remove pipe_label;
- remove pipe_cmd;
- remove burst_label;
- remove burst_opts;
- remove dist_label;
- remove dist_opts;
- remove sort_label;
- remove sort_opts;
- }
- if (dialog_type == REFILE) {
- refile_folder = last_refile_folder;
- display refile_label;
- display refile_folder;
- }
- else if (dialog_type == COMP) {
- comp_opts = last_comp_opts;
- display comp_label;
- display comp_opts;
- }
- else if (dialog_type == FORW) {
- forw_opts = last_forw_opts;
- display forw_label;
- display forw_opts;
- }
- else if (dialog_type == REPL) {
- repl_opts = last_repl_opts;
- display repl_label;
- display repl_opts;
- }
- else if (dialog_type == SEARCH) {
- search_regex = last_search_regex;
- display search_label;
- display search_regex;
- }
- else if (dialog_type == NEW_FOLDER) {
- new_folder = last_new_folder;
- display new_folder_label;
- display new_folder;
- }
- else if (dialog_type == PIPE) {
- pipe_cmd = last_pipe_cmd;
- display pipe_label;
- display pipe_cmd;
- }
- else if (dialog_type == BURST) {
- burst_opts = last_burst_opts;
- display burst_label;
- display burst_opts;
- }
- else if (dialog_type == DIST) {
- dist_opts = last_dist_opts;
- display dist_label;
- display dist_opts;
- }
- else if (dialog_type == SORT) {
- sort_opts = last_sort_opts;
- display sort_label;
- display sort_opts;
- }
- }
- close {
- if (dialog_type == REFILE) {
- remove refile_label;
- remove refile_folder;
- }
- else if (dialog_type == COMP) {
- remove comp_label;
- remove comp_opts;
- }
- else if (dialog_type == FORW) {
- remove forw_label;
- remove forw_opts;
- }
- else if (dialog_type == REPL) {
- remove repl_label;
- remove repl_opts;
- }
- else if (dialog_type == SEARCH) {
- remove search_label;
- remove search_regex;
- }
- else if (dialog_type == NEW_FOLDER) {
- remove new_folder_label;
- remove new_folder;
- }
- else if (dialog_type == PIPE) {
- remove pipe_label;
- remove pipe_cmd;
- }
- else if (dialog_type == BURST) {
- remove burst_label;
- remove burst_opts;
- }
- else if (dialog_type == DIST) {
- remove dist_label;
- remove dist_opts;
- }
- else if (dialog_type == SORT) {
- remove sort_label;
- remove sort_opts;
- }
- }
- gadgets
- label refile_label
- at 5 5
- "Choose folder to refile to"
- end_label
- button
- normal "OK" {
- if (dialog_type == REFILE) {
- refile_cmd = format("r%s\n", refile_folder);
- send(refile_cmd);
- last_refile_folder = refile_folder;
- }
- else if (dialog_type == COMP) {
- comp_cmd = format("c%s\n", comp_opts);
- send(comp_cmd);
- last_comp_opts = comp_opts;
- }
- else if (dialog_type == FORW) {
- forw_cmd = format("f%s\n", forw_opts);
- send(forw_cmd);
- last_forw_opts = forw_opts;
- }
- else if (dialog_type == REPL) {
- repl_cmd = format("a%s\n", forw_opts);
- send(repl_cmd);
- last_repl_opts = repl_opts;
- }
- else if (dialog_type == SEARCH) {
- search_cmd = format("%s%s\n",
- search_dir, search_regex);
- send(search_cmd);
- last_search_regex = search_regex;
- }
- else if (dialog_type == NEW_FOLDER) {
- new_folder_cmd = format("g%s\n",
- new_folder);
- send(new_folder_cmd);
- last_new_folder = new_folder;
- }
- else if (dialog_type == PIPE) {
- pipe_cmd_cmd = format("|%s\n",
- pipe_cmd);
- send(pipe_cmd_cmd);
- last_pipe_cmd = pipe_cmd;
- }
- else if (dialog_type == BURST) {
- burst_cmd = format("b%s\n", burst_opts);
- send(burst_cmd);
- last_burst_opts = burst_opts;
- }
- else if (dialog_type == DIST) {
- dist_cmd = format("t%s\n", dist_opts);
- send(dist_cmd);
- last_dist_opts = dist_opts;
- }
- else if (dialog_type == SORT) {
- sort_cmd = format("S%s\n", sort_opts);
- send(sort_cmd);
- last_sort_opts = sort_opts;
- }
- remove dialog_box;
- }
- end_button
- text refile_folder
- display 20
- completion "\n\e"
- label "Folder:"
- action {
- refile_cmd = format("r%s\n", refile_folder);
- send(refile_cmd);
- last_refile_folder = refile_folder;
- remove dialog_box;
- }
- end_text
- button
- normal "Cancel" {
- remove dialog_box;
- }
- end_button
- label comp_label
- at 5 5
- "Choose arguments for comp"
- end_label
- label forw_label
- at 5 5
- "Choose arguments for forw"
- end_label
- label repl_label
- at 5 5
- "Choose arguments for repl"
- end_label
- label search_label
- at 5 5
- "Subject line search"
- end_label
- label new_folder_label
- at 5 5
- "Choose new folder"
- end_label
- label pipe_label
- at 5 5
- "Pipe message to command"
- end_label
- label burst_label
- at 5 5
- "Choose arguments for burst"
- end_label
- label dist_label
- at 5 5
- "Choose arguments for dist"
- end_label
- label sort_label
- at 5 5
- "Choose arguments for sortm"
- end_label
- text comp_opts
- at 5 30
- display 20
- completion "\n\e"
- label "Arguments:"
- action {
- comp_cmd = format("c%s\n", comp_opts);
- send(comp_cmd);
- last_comp_opts = comp_opts;
- remove dialog_box;
- }
- end_text
- text forw_opts
- at 5 30
- display 20
- completion "\n\e"
- label "Arguments:"
- action {
- forw_cmd = format("f%s\n", forw_opts);
- send(forw_cmd);
- last_forw_opts = forw_opts;
- remove dialog_box;
- }
- end_text
- text repl_opts
- at 5 30
- display 20
- completion "\n\e"
- label "Arguments:"
- action {
- repl_cmd = format("a%s\n", repl_opts);
- send(repl_cmd);
- last_repl_opts = repl_opts;
- remove dialog_box;
- }
- end_text
- text search_regex
- at 5 30
- display 20
- completion "\n\e"
- label "Expression:"
- action {
- search_cmd = format("%s%s\n", search_dir,
- search_regex);
- send(search_cmd);
- last_search_regex = search_regex;
- remove dialog_box;
- }
- end_text
- text new_folder
- at 5 30
- display 20
- completion "\n\e"
- label "Folder:"
- action {
- new_folder_cmd = format("g%s\n", new_folder);
- send(new_folder_cmd);
- last_new_folder = new_folder;
- remove dialog_box;
- }
- end_text
- text pipe_cmd
- at 5 30
- display 20
- completion "\n\e"
- label "Command:"
- action {
- pipe_cmd_cmd = format("|%s\n", pipe_cmd);
- send(pipe_cmd_cmd);
- last_pipe_cmd = pipe_cmd;
- remove dialog_box;
- }
- end_text
- text burst_opts
- at 5 30
- display 20
- completion "\n\e"
- label "Arguments:"
- action {
- burst_cmd = format("b%s\n", burst_opts);
- send(burst_cmd);
- last_burst_opts = burst_opts;
- remove dialog_box;
- }
- end_text
- text dist_opts
- at 5 30
- display 20
- completion "\n\e"
- label "Arguments:"
- action {
- dist_cmd = format("t%s\n", dist_opts);
- send(dist_cmd);
- last_dist_opts = dist_opts;
- remove dialog_box;
- }
- end_text
- text sort_opts
- at 5 30
- display 20
- completion "\n\e"
- label "Arguments:"
- action {
- sort_cmd = format("S%s\n", sort_opts);
- send(sort_cmd);
- last_sort_opts = sort_opts;
- remove dialog_box;
- }
- end_text
- end_gadgets
- end_dialog
-
- /*
- * Move cursor to message that the mouse points to.
- */
-
- mouse
- base 0 characters
- button left
- normal {
- scanline = mouse_y - 1;
- send "H";
- while (scanline-- > 1) {
- send "j";
- }
- }
- shift {
- scanline = mouse_y - 1;
- send "H";
- while (scanline-- > 1) {
- send "j";
- }
- send " ";
- }
- end_button
- end_mouse
- END-OF-TOOLTOOL-SCRIPT
-
- exec tooltool -f $TMP "$@"
-